# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def view_attr(a,f)
    print(" #{a.name}\t\t\t\=\t\t\t#{a.type}\n")
    view="<b>#{a.name}</b>"
    if(a.type == String)
      view +=  f.text_field( a.name)
    elsif(a.type==  DataMapper::Types::Text)
      view +=  f.text_area(a.name)
    
    #elsif(a.type== DataMapper::Types::Link)
    #  view +=  f.text_field(a.name)
      
    elsif(a.type== DataMapper::Types::Boolean)
      view += f.check_box( a.name)
    elsif(a.type== DataMapper::Types::Serial)
      #view += f.text_field( a.name)
    elsif(a.type== Date)
      view +=  f.date_select( a.name)
    elsif(a.type== DateTime)
      #view +=  f.datetime_select( a.name)
    else
      view +=  f.text_field(a.name)
    end
    return view
  end
  def view_attr_on_iphone(a,f)
    print(" #{a.name}\t\t\t\=\t\t\t#{a.type}\n")
    view="<li class='infolist'>
	    	<div class='infotitle'>#{a.name}</div>
                <div class='infovalue'>"

    if(a.type == String)
      view +=  f.text_field( a.name)
    elsif(a.type==  DataMapper::Types::Text)
      view +=  f.text_area(a.name)

    elsif(a.type== DataMapper::Types::Link)
      view +=  f.text_field(a.name)

    elsif(a.type== DataMapper::Types::Boolean)
      view += f.check_box( a.name)
    elsif(a.type== DataMapper::Types::Serial)
      #view += f.text_field( a.name)
    elsif(a.type== Date)
      view +=  "<input type='date' />"#f.date_select( a.name)
    elsif(a.type== DateTime)
      view +=  "<input type='date' />"#view +=  f.datetime_select( a.name)
    else
      view +=  f.text_field(a.name)
    end
    view+="</div>
		</li>"
    return view
  end

  def show_attr_on_iphone(m,a)
    print(" #{a.name}\t\t\t\=\t\t\t#{a.type}\n")

    if(a.type == String)
      value = m[a.name]
    elsif(a.type==  DataMapper::Types::Text)
      value  =[a.name]
    elsif(a.type==  DataMapper::Types::Link)
      value  ="<a href='#{m[a.name]}' target>More</a>"
#    elsif(a.type==  DataMapper::Types::Date)
#      value  ="<a href='#{m[a.name]}' target>More</a>"
#    elsif(a.type==  DataMapper::Types::DateTime)
#      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::Boolean)
       if m[a.name]
        value  ="<input type='checkbox' checked disabled />"
      else
        value  ="<input type='checkbox'  disabled />"
      end
    elsif(a.type==  DataMapper::Types::Serial)
      value  ="#{m[a.name]}"
     elsif(a.type==  DataMapper::Types::Blob)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  Date)
      value  ="#{m[a.name]}"
    elsif(a.type==  DateTime)
      value  =m[a.name].strftime('%Y-%m-%d %H:%M:%S')
    elsif(a.type==  Integer)
      value  ="#{m[a.name]}"
    elsif(a.type==  Float)
      value  ="'#{m[a.name]}'"
    else
      value=  m[a.name]
    end


    view="<li class='infolist'>
	    	<div class='infotitle'>#{a.name}</div>
                <div class='infovalue'>#{value}</div>
		</li>"

    return view
  end

 def show_attr(m,a)
    print(" #{a.name}\t\t\t\=\t\t\t#{a.type}\n")

    if(a.type == String)
      value = m[a.name]
    elsif(a.type==  DataMapper::Types::Text)
      value  =[a.name]
    elsif(a.type==  DataMapper::Types::Link)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::Date)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::DateTime)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::Boolean)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::Serial)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  Date)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DateTime)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::Link)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::Link)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    elsif(a.type==  DataMapper::Types::Link)
      value  ="<a href='#{m[a.name]}' target>More</a>"
    else
      value=  m[a.name]
    end


    view="<li class='infolist'>
	    	<div class='infotitle'>#{a.name}</div>
                <div class='infovalue'>#{value}</div>
		</li>"

    return view
  end


end

